<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head> 
   <meta charset="UTF-8">
   <%@ include file="/WEB-INF/views/include/head.jsp"%>
   <link rel="stylesheet" href="${ctxStatic}/css/common_erp.css">
   <link rel="stylesheet" href="${ctxStatic}/css/layerSm.css">
   <c:set value="<%=ResourcesUtil.getConfig(\"clothes_out_category_samply\")%>" var="varClothesOutSamply" />
   <c:set value="<%=ResourcesUtil.getConfig(\"clothes_out_category_order\")%>" var="varClothesOutOrder" />
   <script src="${ctxStatic}/js/jquery-1.9.1.min.js"></script>
   <script src="${ctxStatic}/js/layer.js"></script>
   <script src="${ctxStatic}/js/style.js"></script>
   <script src="${ctxStatic}/jquery-barcode/jquery-barcode.js" type="text/javascript"></script>
   <script type="text/javascript">
   // 样品成衣出库
   var clothesOutSamply = "${varClothesOutSamply}";
   // 订单成衣出库
   var clothesOutOrder = "${varClothesOutOrder}";

	$(document).ready(function(){
		$("#outboundCategory").select2();
        $("#styleId").select2();
		$("#sampleRequestId").select2();
        $("#contractId").select2();
		selectListControl();
	});
	
	// 下拉列表制御
	function selectListControl(){
		var vOutCatagory = $("#outboundCategory").val();
		if(vOutCatagory == clothesOutOrder){
            $('#orderShow').show();
            $('#samplyShow').hide();
            $('#divStyleId').show();
			$('#styleId').attr('disabled',true);
		}else if(vOutCatagory == clothesOutSamply ){
            $('#orderShow').hide();
            $('#divStyleId').show();
            $('#samplyShow').show();
            $('#samplyShow').attr('disabled',false);
            $('#styleId').attr('disabled',true);
		}else{
            $('#orderShow').hide();
            $('#samplyShow').hide();
            $('#divStyleId').hide();
		}
	}
	
    function delAllDetails(){
        // 调用后台更新数据
        $.post("${ctx}/slopwork/outrequest/delAllDetails",'',function(result) {
            // 回调函数赋值
            var h = $(callBackHtml(result)).find("#tableRequestDetails").html();
            $('#tableRequestDetails').html(h);
        }, 'html');
    }

	// 合同编号联动
	function contractSelFun(){
			// 合同编号联动
			var paramContractId = $("#contractId").val();
			var param={"contractId":paramContractId};
	        $.post("${ctx}/slopwork/outrequest/selContract",param,function(result){
	        	// 回调函数赋值
	            var hNo = $(callBackHtml(result)).find("#divInventoryRequestNo").html();
	            $('#divInventoryRequestNo').html(hNo);
			    var hStyle = $(callBackHtml(result)).find("#divStyleId").html();
			    $('#divStyleId').html(hStyle);
			    $('#styleId').select2();
			    $('#styleId').attr('disabled',false);

				var hDetails = $(callBackHtml(result)).find("#tableRequestDetails").html();
				$('#tableRequestDetails').html(hDetails);
				}, 'html');
	}
	
	// 样品需求联动
	function samplyOrderIdFun(){
		// 样品需求联动
		var paramsampleRequestId = $("#sampleRequestId").val();
		var param={"sampleRequestId":paramsampleRequestId};
        $.post("${ctx}/slopwork/outrequest/selContractProcess",param,function(result){
            var hNo = $(callBackHtml(result)).find("#divInventoryRequestNo").html();
            $('#divInventoryRequestNo').html(hNo);
		    var hStyle = $(callBackHtml(result)).find("#divStyleId").html();
		    $('#divStyleId').html(hStyle);
		    $('#styleId').select2();
            $('#styleId').attr('disabled',true);
            var hDetails = $(callBackHtml(result)).find("#tableRequestDetails").html();
            $('#tableRequestDetails').html(hDetails);
			}, 'html');
	}
	
	// 款式联动
	function styleSelFun(){		
		// 款式联动联动
		var paramStyleId = $("#styleId").val();
        var paramStyleNo = $("#styleNo").val();
		var param={"styleId":paramStyleId,"styleNo":paramStyleNo};
        $.post("${ctx}/slopwork/outrequest/selStyle",param,function(result){            
        	// 回调函数赋值
            var hNo = $(callBackHtml(result)).find("#divInventoryRequestNo").html();
            $('#divInventoryRequestNo').html(hNo);

	        
			var hDetails = $(callBackHtml(result)).find("#tableRequestDetails").html();
			$('#tableRequestDetails').html(hDetails);
			
			}, 'html');
	}
	
    //保存方法
    var saveForm={
         t:null,
         save:function(t){
        	 
         	 if($("#tableRequestDetails tr").length==0){
        		 layer.msg('<spring:message code="SlopworkOutrequest_create_msg_details"/>', {time:1000});
        		 return;
        	 } 
        	 
              $(t).attr("disabled",true);
              this.t=t;
              // 表单验证
              $("#inputForm").validate({
              fail: function(element,e) {  
                  $(saveForm.t).attr("disabled",false);
              },
                   submitHandler: function() {
                	   $('#styleId').attr('disabled',false);
                   	   // 格式化，去除逗号
                       formUnFormat($("#inputForm"));
                        // 从表单获取数据信息
                        var params = $("#inputForm").serialize();
                        // 调用后台保存方法
                        $.post("${ctx}/slopwork/outrequest/save",params,function(result){
                             // 提示信息
                             tipParent(result.message);
                             // 返回状态
                             if(result.statusCode==STATUSCODEOK){
                                 // 刷新页面
                                 window.parent.frames[0].searchListForm();
                                 closeWin();
                             }else{
                                  $(saveForm.t).attr("disabled",false);
                             }
                        },'json'); 
                   }
              });
              // 提交表单
              $("#inputForm").submit(); 
         } 
    }
    
    function funFormatNumber(obj){
    	
    	var intReg = /^[0-9]+$/;   
    	var floatReg = /^[0-9]+.?[0-9]*$/;   
    	var s = $(obj).val();
        
    	// 整数
    	if(intReg.test(s)){
    		var numberTen = /^[0-9]{1,7}$/;
			if (!numberTen.test(s)){
				$(obj).val('');
			}
		// 小数	
    	}else if(floatReg.test(s)){
    		var numberVerification = /^[0-9]{1,7}.?[0-9]{0,3}$/;  
			if (!numberVerification.test(s)){
				$(obj).val('');
			}
    	}else{
    		$(obj).val('');
    	}
    	formatNumber(obj);
    }
    function checkMoney(t){
        var varRequestOutQuantity = parseInt(t.value)
        var varclothsQuantity = parseInt($(t.parentNode.parentNode.parentNode).find("#clothsQuantity").val())
       if (varRequestOutQuantity > varclothsQuantity){
           layer.msg('<spring:message code="please_outbound_check_alert"/>', {time:1000});
           return;
       }
    }
	</script>
</head>
<body>
<div class="layerHeader clearfix">
	<p class="headerTitle"><spring:message code="SlopworkOutrequest_show_head" /></p>
    <div class="headerButton clearfix">
        <!-- 保存 -->
        <button type="button" onclick="saveForm.save(this)"><spring:message code="common_save"/></button>
        <!-- 取消 -->
        <button onclick="closeWin()"><spring:message code="btn_cancle"/></button>
    </div>
</div>
<form id="inputForm" method="post">
<c:set value="<%=ResourcesUtil.getConfig(\"clothes_out_category\")%>" var="varInventoryCategory" />
<input type="hidden" id="id" name="id" value="${slopworkOutrequest.id}"/>
    <input type="hidden" id="ostockBarCode" name="ostockBarCode" value="${slopworkOutrequest.ostockBarCode}">

<div class="smOrderBox">
    <div class="items clearfix">
        <div class="col-33 clearfix" id="divInventoryRequestNo">
            <!-- 出库单号 -->
            <p class="tit"><spring:message code="SlopworkOutrequest_show_inventoryRequestNo" /></p>
            <input style="background-color:inherit;color:#333;" type="text" id="outboundRequestNo" name="outboundRequestNo" value="${slopworkOutrequest.outboundRequestNo}" readonly="true">
            <!--外发加工合同ID-->
            <input type="hidden" id="ocontractProcessId" name="ocontractProcessId" value="${slopworkOutrequest.ocontractProcessId}">
            <!--生产制单ID-->
            <input type="hidden" id="oproductionId" name="oproductionId" value="${slopworkOutrequest.oproductionId}">
            <!--合同订单ID -->
            <input type="hidden" id="indentId" name="indentId" value="${slopworkOutrequest.indentId}">
        </div>
        <div class="col-33 clearfix">
            <!-- 出库类别 -->
            <p class="tit"><spring:message code="SlopworkOutrequest_show_inventoryCategory" /></p>
            <select style="width:52%" id="outboundCategory" name="outboundCategory" onchange="selectListControl();">
                <option value=""><spring:message code="customer_pleaseChoose"/></option>
                <c:forEach items="${fns:getDictList(varInventoryCategory)}"   var="inventoryCategoryInfo">
                    <option <c:if test="${fn:split(slopworkOutrequest.outboundCategory,'-')[1] eq inventoryCategoryInfo.itemValue}">selected="selected"</c:if> value="${inventoryCategoryInfo.itemCode}-${inventoryCategoryInfo.itemValue}" >
                            ${inventoryCategoryInfo.itemName}
                    </option>
                </c:forEach>
            </select>
        </div>
    </div>
    <div class="items clearfix">
        <div id="orderShow">
            <div class="col-33 clearfix">
            <!-- 合同编号 -->
            <p class="tit" style="width:75px;"><spring:message code="SlopworkOutrequest_show_order" /></p>
            <select style="width:52%" id="contractId" name="contractId" onchange="contractSelFun();">
                <option value=""><spring:message code="customer_pleaseChoose"/></option>
                <c:forEach items="${slopworkOutrequest.contractList}" var="contractListInfo">
                    <option <c:if test="${slopworkOutrequest.contractId eq contractListInfo.contractId}">selected="selected"</c:if> value="${contractListInfo.contractId}" >
                            ${contractListInfo.contractNo}
                    </option>
                </c:forEach>
            </select>
        </div>
        </div>
        <div id="samplyShow">
            <div class="col-33 clearfix" id="divContractProcessId">
            <!-- 样品需求订单  -->
            <p class="tit" style="width:75px;"><spring:message code="customer_styleNo_choose" /> </p>
            <select style="width:52%" id="sampleRequestId" name="sampleRequestId" onchange="samplyOrderIdFun();">
               <option value=""><spring:message code="customer_pleaseChoose"/></option>
               <c:forEach items="${slopworkOutrequest.samplyOrderList}" var="samplyOrderInfo">
                  <option <c:if test="${slopworkOutrequest.sampleRequestId eq samplyOrderInfo.sampleRequestId}">selected="selected"</c:if> value="${samplyOrderInfo.sampleRequestId}" >
                     ${samplyOrderInfo.sampleRequestNo}
                  </option>
               </c:forEach>
            </select>
        </div>
        </div>
        <div class="col-33 clearfix" id="divStyleId">
            <!-- 款式 -->
            <p class="tit"><spring:message code="SlopworkOutrequest_show_style" /></p>
            <select style="width:52%" id="styleId" name="styleId" onchange="styleSelFun();">
               <option value=""><spring:message code="customer_pleaseChoose"/></option>
               <c:forEach items="${slopworkOutrequest.ostyleList}" var="styleInfo">
                  <option <c:if test="${slopworkOutrequest.styleId eq styleInfo.styleId}">selected="selected"</c:if> value="${styleInfo.styleId}" > 
                     ${styleInfo.ocustomerStyleNo}
                  </option>
               </c:forEach>
            </select>
        </div>
    </div>
</div>
<div class="tableArea">
    <div class="tableScrollSm" style="overflow:auto;width:875px;height:420px;">
        <table cellpadding="0" class="tableHead">
            <thead>
            <tr>
                <!-- 客户订单号 -->
                <th><p class="width-250px"><spring:message code="slopworkInRequest_show_list_customerContractNo" /></p></th>
                <!-- 颜色-->
                <th><p class="width-120px"><spring:message code="slopworkInRequest_show_list_color" /></p></th>
                <!-- 尺码 -->
                <th><p class="width-120px"><spring:message code="slopworkInRequest_show_list_size" /></p></th>
                <!-- 订单数量 -->
                <th><p class="width-120px"><spring:message code="slopworkInRequest_show_list_indentQuantity" /></p></th>
                <!-- 库存数量 -->
                <th><p class="width-120px"><spring:message code="slopworkInRequest_show_list_quantity" /></p></th>
                <!-- 入库数量-->
                <th><p class="width-120px"><spring:message code="SlopworkOutrequest_show_list_requestQuantity" /></p></th>
            </tr>
            </thead>
        </table>
        <table cellpadding="0" class="tableBody" id="tableRequestDetails">
        <c:if test="${not empty slopworkOutrequest.requestOutDetailsList}">
            <tbody>
            <c:forEach items="${slopworkOutrequest.requestOutDetailsList}" var="outrequestDetailsInfo" varStatus="status">
            <tr>
                <!-- 客户订单号 -->
                <td><p class="width-250px">${outrequestDetailsInfo.customerContractNo}</p></td>
                <!-- 颜色-->
                <td><p class="width-120px">${outrequestDetailsInfo.styleColor}</p></td>
                <!-- 尺码 -->
                <td><p class="width-120px">${fns:getDictName(outrequestDetailsInfo.styleSize)}</p></td>
                <!-- 订单数量 -->
                <td><p class="width-120px"><fmt:formatNumber value="${outrequestDetailsInfo.oindentQuantity}" pattern="#,##0"/></p></td>
                <!-- 库存数量 -->
                <td><p class="width-120px"><fmt:formatNumber value="${outrequestDetailsInfo.clothsQuantity}" pattern="#,##0"/></p></td>
                <!-- 入库数量-->
                <td><p class="width-120px"><input type="tel" name="requestOutDetailsList[${status.index}].requestOutQuantity" value="<fmt:formatNumber value="${outrequestDetailsInfo.requestOutQuantity}" pattern="#,##0.###"/>" maxlength="11" onblur="funFormatNumber(this);" onfocus="unFormat(this)" onchange="checkMoney(this)"></p></td>
                <input type="hidden" id="clothsQuantity" value="${outrequestDetailsInfo.clothsQuantity}"/>
                <input type="hidden" name="requestOutDetailsList[${status.index}].styleId" value="${outrequestDetailsInfo.styleId}"/>
                <input type="hidden" name="requestOutDetailsList[${status.index}].styleSize" value="${outrequestDetailsInfo.styleSize}"/>
                <input type="hidden" name="requestOutDetailsList[${status.index}].styleSizeGroup" value="${outrequestDetailsInfo.styleSizeGroup}"/>
                <input type="hidden" name="requestOutDetailsList[${status.index}].styleColor" value="${outrequestDetailsInfo.styleColor}"/>
                <input type="hidden" name="requestOutDetailsList[${status.index}].indentId" value="${outrequestDetailsInfo.indentId}"/>
            </tr>
            </c:forEach>
            </tbody>

        </c:if>    
        </table>
    </div>
</div>
</form>
</body>
</html>